package com.framework;


import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

class ComponentRegistry {
    private Map<String, Component<?, ?>> components = new ConcurrentHashMap<>();
    
    public void registerComponent(Component<?, ?> component) {
        components.put(component.getType(), component);
    }
    
    public void registerComponent(Component<?, ?> component, String alias) {
        components.put(alias, component);
    }
    
    @SuppressWarnings("unchecked")
    public <T, R> Component<T, R> getComponent(String typeOrAlias) {
        Component<?, ?> comp = components.get(typeOrAlias);
        if (comp != null) {
            return (Component<T, R>) comp;
        }
        throw new ComponentNotFoundException("Component not found: " + typeOrAlias);
    }
    
    static class ComponentNotFoundException extends RuntimeException {
        public ComponentNotFoundException(String message) {
            super(message);
        }
    }
}